package com.abc.cloud.service.impl;

import com.abc.cloud.dto.sensitiveword.SensitiveWordUser;
import com.abc.cloud.entity.UserEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Query;

import com.abc.cloud.dao.SensitiveWordDao;
import com.abc.cloud.entity.SensitiveWordEntity;
import com.abc.cloud.service.SensitiveWordService;


@Service("sensitiveWordService")
public class SensitiveWordServiceImpl extends ServiceImpl<SensitiveWordDao, SensitiveWordEntity> implements SensitiveWordService {

    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        IPage<SensitiveWordEntity> page = this.page(
                new Query<SensitiveWordEntity>().getPage(params),
                new QueryWrapper<SensitiveWordEntity>()
        );

        return new PageUtil(page);
    }

    @Override
    public PageUtil getWordList(Map<String, Object> params) {
        Integer pageSize = Integer.parseInt((String)(params.get("pageSize")));   //一页展示多少条
        pageSize = pageSize > 0 ? pageSize : 1;
        Integer currPage = Integer.parseInt((String)params.get("currPage"));     //当前页数
        String searchContent = (String)params.get("searchContent");
        Integer totalCount = baseMapper.getCount(searchContent);        //总记录数
        Integer totalPage = totalCount / pageSize + (totalCount%pageSize > 0 ? 1 : 0);       //总页数

        List<SensitiveWordUser> wordList = baseMapper.getWordList((currPage-1)*pageSize ,pageSize,searchContent);

        // 这里面查出来的
        PageUtil pageUtil = new PageUtil(wordList,pageSize,currPage,totalCount,totalPage);
        return pageUtil;
    }

}